package com.demo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.domain.User;
import com.demo.domain.ro.ModifyUserInfoRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {
    //    查找所有用户
    @Select("select * from tb_user")
    public List<User> selectAll();

    /*
    通过用户账号uid查找用户
    * */
    @Select("select * from tb_user where u_id = #{uid}")
    @Results({@Result(column = "u_id", property = "uid"),
            @Result(column = "u_nickname", property = "nickname"),
            @Result(column = "u_realname", property = "realname"),
            @Result(column = "u_gender", property = "gender"),
            @Result(column = "u_phone", property = "phone"),
            @Result(column = "u_intro", property = "intro"),
            @Result(column = "u_ability", property = "ability"),
            @Result(column = "u_mail", property = "email"),
            @Result(column = "u_pwd", property = "password"),
            @Result(column = "u_alive", property = "alive")
    })
    public ModifyUserInfoRequest findByUserid(Long uid);


    /*
    判断用户输入密码与数据库中密码是否一致
    * */
    @Select("select * from tb_user where u_id = #{uid}")
    public User findByUidAndPassword(Long uid);

    //  更新用户信息
// 更新用户信息
    @Update("update tb_user set u_nickname = #{unickname},u_realname = #{urealname} "
            + ",u_gender = #{ugender},u_phone = #{uphone},u_mail = #{umail} "
            + ",u_intro = #{uintro},u_ability = #{uability} where u_id = #{uid}")
    public Integer updateInfo(Long uid, String unickname, String urealname, String ugender,
                              String uphone, String umail, String uintro, String uability);

    /*
通过用户账号uid查找用户个人信息
* */
    @Select("select u_id,u_nickname,u_realname,u_gender,u_phone,u_mail,u_intro,u_ability from "
            + "tb_user where u_id = #{uid}")
    public User findUserInfoByUserid(Long uid);

    @Select("select u_realname from tb_user where u_id=#{uid}")
    public String selectRealNameByUid(Long uid);

    @Select("SELECT u_id FROM tb_user where u_nickname=#{unickname}")
    Long selectToUidByUncikName(String unickname);

    @Select("SELECT u_mail FROM tb_user WHERE"
            + " u_id=#{uid}")
    String getEmail(Long uid);

    @Select("SELECT u_nickname FROM tb_user WHERE"
            + " u_id=#{uid}")
    String getNickname(Long uid);

    @Select("SELECT COUNT(*) FROM tb_user WHERE"
            + " u_mail=#{umail}")
    int countEmail(String umail);

    @Select("SELECT COUNT(*) FROM tb_user WHERE"
            + " u_nickname=#{unickname}")
    int countNickname(String unickname);



}
